import { userMsg } from '@/api/login'
export default {
  namespaced: true,
  state: {
    userInfo: {}
  },
  mutations: {
    setMsg (state, msg) {
      state.userInfo = msg
    }
  },
  getters: {
    userName (state) {
      return state.userInfo.nickname || state.userInfo.username
    },
    // 动态计算文本头像
    textAvatar (state) {
      return state.userInfo.username ? state.userInfo.username.charAt(0).toUpperCase() : ''
    }
  },
  actions: {
    async getMsg ({ commit }) {
      const { data } = await userMsg()
      if (data.code === 0) {
        commit('setMsg', data.data)
      } else {
        this.$message.error(data.message)
      }
    }
  }
}
